package com.zhipu.resetbalance.ui.start;

import android.Manifest;
import android.os.Bundle;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.zhipu.resetbalance.R;
import com.zhipu.resetbalance.databinding.ActivityStartBinding;
import com.zhipu.resetbalance.ui.BaseActivity;
import com.zhipu.resetbalance.ui.home.HomeActivity;
import com.zhipu.resetbalance.utils.DataGenerateUtils;
import com.zhipu.resetbalance.utils.PermissionsUilst;

import java.util.List;

public class StartActivity extends BaseActivity<ActivityStartBinding> {


    @Override
    public int initContentView(Bundle savedInstanceState) {

        return R.layout.activity_start;
    }


    @Override
    public void initCreate() {
        super.initCreate();
        setTheme(R.style.NoStatusTheme1);
    }



    @Override
    public void initView() {
        super.initView();



    }


    @Override
    public void initData() {
        super.initData();
        /**
         * 人员数据生成
         */
        DataGenerateUtils.dataPersonnel();
        /**
         * 编号数据生成
         */
        DataGenerateUtils.dataNumber();

    }


    @Override
    public void initViewObservable() {
        super.initViewObservable();
        /**
         * 判断权限
         */
        if(PermissionsUilst.setAuthority(mContext)){


        }else {
            XXPermissions.with(mContext).permission(Permission.MANAGE_EXTERNAL_STORAGE).request(new OnPermissionCallback() {
                @Override
                public void onGranted(List<String> permissions, boolean all) {
                    if (all) {
                        ActivityUtils.startActivity(HomeActivity.class);
                        ActivityUtils.finishActivity(StartActivity.class);
                    }else {
                        ToastUtils.showShort("部分权限未正常授予");
                    }
                }
                @Override
                public void onDenied(List<String> permissions, boolean never) {
                    if (never) {
                        ToastUtils.showShort("被永久拒绝授权，请手动授予存储权限");
                        // 如果是被永久拒绝就跳转到应用权限系统设置页面
                        XXPermissions.startPermissionActivity(StartActivity.this, permissions);
                    } else {
                        ToastUtils.showShort("获取存储权限失败");
                    }
                }
            });
        }


    }
}
